/*
 * This calendar application is brought to you
 * by Group 3 of User Interface Programming II, vt11.
 *
 * Group Members:
 * Pooya | Flora | Monica | Can
 */
package Beans;

import java.sql.*;

/**
 *
 * @author Pooya
 */
public class UserBean {

    enum UserType {

        User,
        Admin
    }
    private int id;
    private String name;
    private String address;
    private UserType type;
    private String email;
    private String userName;
    private String password;
    private Connection con;
    private String url;
    private Statement SQLQuery;

    public void UserBean(String url) {
        this.url = url;
    }

    public int getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public void setName(String newValue) {
        name = newValue;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String newValue) {
        address = newValue;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String newValue) {
        email = newValue;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String newValue) {
        userName = newValue;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String newValue) {
        password = newValue;
    }

    public UserType getType() {
        return type;
    }

    public void setType(UserType newValue) {
        type = newValue;
    }

    public boolean validate() throws SQLException {
        Boolean result = false;
        ResultSet rs = null;
        String query = "SELECT * FROM USERS";
        query += " WHERE username = " + getUserName() + " AND password = " + getPassword();

        try {
            Class.forName("com.mysql.jdbc.Driver");
            con = DriverManager.getConnection(url);

            SQLQuery = con.createStatement();
            rs = SQLQuery.executeQuery(query);

            result = rs.next();
        } catch (Exception e) {
        } finally {
            rs.close();
            con.close();
        }

        return result;
    }
}
